/*
 * joy_platform.h
 *
 *  Created on: Dec 4, 2012
 *      Author: Michiel Hegemans
 */

#ifndef JOY_PLATFORM_H_
#define JOY_PLATFORM_H_

#define STEP 0.1

#include <ros/ros.h>
#include <sensor_msgs/Joy.h>

#include "PS3Controller/PS3_buttons.h"
#include "topic/topic.h"

class JoyPlatform
{
  protected:
	ros::NodeHandle nh_;
	ros::Subscriber joy_sub_;
	ros::Publisher  vel_pub_;

	double forward_vel_, forward_max_, turn_rate_, turn_max_;

  protected:
	/// Called when a new joystick input is available
	/**
	 * Sends the new velocity to the base controller node. The velocity depends cubically on the joystick input.
	 * \param msg Pointer to Joy message, containing the button status
	 * The buttons used are indices 1 and 2, the left analog stick Y and right analog stick X directions.
	 */
	void joyCallback(const sensor_msgs::Joy::ConstPtr &msg);

  public:
	JoyPlatform() : nh_("~"), forward_vel_(0), forward_max_(0), turn_rate_(0), turn_max_(0)
	{
	  init();
	}

	~JoyPlatform()
	{
	  nh_.shutdown();
	}

	/// Initialize
	/** \note Called during construction */
	void init();

	/// Await status and publish commands
	void spin();
};


#endif /* JOY_PLATFORM_H_ */
